package remoteControlSpy;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

import os_listener.OS_Listener;

import com.cloudgarden.resource.SWTResourceManager;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class RemoteControlGUI extends org.eclipse.swt.widgets.Composite {

	private Menu menu1;
	private Button pauseButton;
	private MenuItem aboutMenuItem;
	private MenuItem contentsMenuItem;
	private Menu helpMenu;
	private MenuItem helpMenuItem;
	private Button stopButton;
	private Button startButton;
	private Button continueButton;
	private MenuItem exitMenuItem;
	private MenuItem closeFileMenuItem;
	private MenuItem saveFileMenuItem;
	private MenuItem newFileMenuItem;
	private MenuItem openFileMenuItem;
	private Menu fileMenu;
	private MenuItem fileMenuItem;
	
	private PauseExecuter pe = new PauseExecuter();
	private StopExecuter ste = new StopExecuter();
	private StartExecuter se = new StartExecuter();
	private ContinueExecuter ce = new ContinueExecuter();
	{
		//Register as a resource user - SWTResourceManager will
		//handle the obtaining and disposing of resources
		SWTResourceManager.registerResourceUser(this);
	}

	public RemoteControlGUI(Composite parent, int style) {
		super(parent, style);
		initGUI();
	}
	
	/**
	* Initializes the GUI.
	*/
	private void initGUI() {
		try {
			this.setSize(new org.eclipse.swt.graphics.Point(400,300));
			this.setBackground(SWTResourceManager.getColor(192, 192, 192));
			FormLayout thisLayout = new FormLayout();
			this.setLayout(thisLayout);
			{
				startButton = new Button(this, SWT.PUSH | SWT.CENTER);
				FormData startButtonLData = new FormData();
				startButtonLData.left =  new FormAttachment(0, 1000, 41);
				startButtonLData.top =  new FormAttachment(0, 1000, 24);
				startButtonLData.width = 76;
				startButtonLData.height = 24;
				startButton.setLayoutData(startButtonLData);
				startButton.setText("start");
			}
			{
				continueButton = new Button(this, SWT.PUSH | SWT.CENTER);
				FormData continueButtonLData = new FormData();
				continueButtonLData.left =  new FormAttachment(0, 1000, 41);
				continueButtonLData.top =  new FormAttachment(0, 1000, 115);
				continueButtonLData.width = 76;
				continueButtonLData.height = 24;
				continueButton.setLayoutData(continueButtonLData);
				continueButton.setText("continue");
			}
			{
				pauseButton = new Button(this, SWT.PUSH | SWT.CENTER);
				FormData pauseButtonLData = new FormData();
				pauseButtonLData.left =  new FormAttachment(0, 1000, 41);
				pauseButtonLData.top =  new FormAttachment(0, 1000, 68);
				pauseButtonLData.width = 76;
				pauseButtonLData.height = 24;
				pauseButton.setLayoutData(pauseButtonLData);
				pauseButton.setText("pause");
			}
			{
				stopButton = new Button(this, SWT.PUSH | SWT.CENTER);
				FormData concreteCommandButtonLData = new FormData();
				concreteCommandButtonLData.left =  new FormAttachment(0, 1000, 41);
				concreteCommandButtonLData.top =  new FormAttachment(0, 1000, 163);
				concreteCommandButtonLData.width = 76;
				concreteCommandButtonLData.height = 24;
				stopButton.setLayoutData(concreteCommandButtonLData);
				stopButton.setText("stop");
			}
			
			
			stopButton.addMouseListener(new MouseListener() {
				
				@Override
				public void mouseUp(MouseEvent arg0) 
				{
					ste.execute();
				}
				
				@Override
				public void mouseDown(MouseEvent arg0) {}
				
				@Override
				public void mouseDoubleClick(MouseEvent arg0) {}
			});
			
			
			startButton.addMouseListener(new MouseListener() {
				
				@Override
				public void mouseUp(MouseEvent arg0) 
				{
					se.execute();
				}
				
				@Override
				public void mouseDown(MouseEvent arg0) {}
				
				@Override
				public void mouseDoubleClick(MouseEvent arg0) {}
			});
			
			
			continueButton.addMouseListener(new MouseListener() {
				
				@Override
				public void mouseUp(MouseEvent arg0) 
				{
					ce.execute();
				}
				
				@Override
				public void mouseDown(MouseEvent arg0) {}
				
				@Override
				public void mouseDoubleClick(MouseEvent arg0) {}
			});
			
			pauseButton.addMouseListener(new MouseListener() {
				
				@Override
				public void mouseUp(MouseEvent arg0) 
				{
					pe.execute();
				}
				
				@Override
				public void mouseDown(MouseEvent arg0) {}
				
				@Override
				public void mouseDoubleClick(MouseEvent arg0) {}
			});
			
			
			{
				menu1 = new Menu(getShell(), SWT.BAR);
				getShell().setMenuBar(menu1);
				{
					fileMenuItem = new MenuItem(menu1, SWT.CASCADE);
					fileMenuItem.setText("File");
					{
						fileMenu = new Menu(fileMenuItem);
						{
							openFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							openFileMenuItem.setText("Open");
						}
						{
							newFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							newFileMenuItem.setText("New");
						}
						{
							saveFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							saveFileMenuItem.setText("Save");
						}
						{
							closeFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							closeFileMenuItem.setText("Close");
						}
						{
							exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
							exitMenuItem.setText("Exit");
						}
						fileMenuItem.setMenu(fileMenu);
					}
				}
				{
					helpMenuItem = new MenuItem(menu1, SWT.CASCADE);
					helpMenuItem.setText("Help");
					{
						helpMenu = new Menu(helpMenuItem);
						{
							contentsMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
							contentsMenuItem.setText("Contents");
						}
						{
							aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
							aboutMenuItem.setText("About");
						}
						helpMenuItem.setMenu(helpMenu);
					}
				}
			}
			this.layout();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	 * @throws InterruptedException 
	*/
	public static void main(String[] args)
	{
		System.out.println("starting the service spy (calling the class os listener)");
		StartExecuter startE = new StartExecuter();
		startE.execute();
		Display display = Display.getDefault();
		Shell shell = new Shell(display);
		RemoteControlGUI inst = new RemoteControlGUI(shell, SWT.NULL);
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.layout();
		if(size.x == 0 && size.y == 0) {
			inst.pack();
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
		shell.open();		
		while (!shell.isDisposed()) 
		{
			if (!display.readAndDispatch())
				display.sleep();
		}
		
		StopExecuter s = new StopExecuter();
		s.execute();
	}
	
}
